package dxn.nl.file.biz;

import io.minio.MinioClient;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@AllArgsConstructor
@Configuration
@EnableConfigurationProperties({MinioProperties.class})
public class MinioAutoConfiguration {
    @Resource
    private final MinioProperties properties;

    @Bean
    //@ConditionalOnMissingBean(MinioTemplate::class)
    @ConditionalOnProperty(name = "minio.url")
    MinioClient minioClient() {
        return MinioClient.builder().endpoint(properties.getUrl()).credentials(properties.getAccessKey(), properties.getSecretKey()).build();
    }
}
